﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Web.SessionState;
namespace VTNT.Presentation.Web.Mods.Core
{
    public class CUrl
    {
        public static string VirtualDirectory
        {
            get
            {
                string virDir = "";
                string APPL_MD_PATH = HttpContext.Current.Request.ServerVariables[2]; //APPL_MD_PATH
                if (APPL_MD_PATH != "")
                {
                    string[] path = APPL_MD_PATH.Split('/');
                    if (path.Length > 0)
                        virDir = path[path.Length - 1];
                }

                return virDir;
            }
        }
        public static string HostName
        {
            get
            {
                string localPath = HttpContext.Current.Request.Url.LocalPath;
                string uri = HttpContext.Current.Request.Url.AbsoluteUri;
                string ret = uri.Substring(0, uri.IndexOf(localPath));

                return ret;
            }
        }
        public static string Domain
        {
            get
            {
                return CUrl.Host.Replace(CUrl.VirtualDirectory + "/", "");
            }
        }
        public static string Host
        {
            get
            {
                string localPath = HttpContext.Current.Request.Url.LocalPath;
                string uri = HttpContext.Current.Request.Url.AbsoluteUri;
                string host = uri.Substring(0, uri.IndexOf(localPath));

                string hostWithVirtualDirectory = host + "/" + (VirtualDirectory == "" ? "" : VirtualDirectory + "/");
                return hostWithVirtualDirectory;
            }
        }
    }
}
